using Domain.Model.Partners;
using Presentation.Web.Client.Areas.SalesManagement.Models;
using Presentation.Web.Client.Models;

namespace Presentation.Web.Client.Areas.PartnersManagement.Models.PartnerDetails
{
    public class PartnerDetailsViewModel
    {
        private readonly PartnerDetailsTabsService _tabsService;

        public PartnerDetailsViewModel()
        {
            _tabsService = new PartnerDetailsTabsService();
        }

        public PartnerDetailsViewModel(Partner partner)
        {
            _tabsService = new PartnerDetailsTabsService();
            CurrentPartner = partner;
        }

        /// <summary>
        /// Current partner object
        /// </summary>
        public Partner CurrentPartner { get; set; }

        /// <summary>
        /// Current partner tab
        /// </summary>
        public PartialViewModelBase CurrentTabViewModel
        {
            get
            {
                if (_currentTabvViewModel == null)
                {
                    _currentTabvViewModel = _tabsService.GetTab(CurrentTabName, CurrentPartner);
                }

                return _currentTabvViewModel;
            }
        }
        private PartialViewModelBase _currentTabvViewModel;

        /// <summary>
        /// Current partner details tab name
        /// </summary>
        public string CurrentTabName
        {
            get { return _currentTabViewName ?? (_currentTabViewName = "General"); }
            set { _currentTabViewName = value; }
        }
        private string _currentTabViewName;


        /// <summary>
        /// Current partner details tab file name
        /// </summary>
        public string  CurrentTabFileName
        {
            get { return _tabsService.GetTabFileName(CurrentTabName); }
        }

        /// <summary>
        /// Navigation items for control panel
        /// </summary>
        public LinksCollectionViewModel ControlPanelActions
        {
            get
            {
                return _controlPanelActions ?? (_controlPanelActions = new SalesViewModel().SalesActionLinks);
            }
        }
        private LinksCollectionViewModel _controlPanelActions;

        /// <summary>
        /// Change current tab viewModel
        /// </summary>
        /// <param name="tabName">New tab name</param>
        public void ChangeCurrentTab(string tabName)
        {
            _currentTabViewName = tabName;
            _currentTabvViewModel = _tabsService.GetTab(tabName, CurrentPartner);
        }


    }
}